package com.itheima;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.itheima.entity.Emp;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class WriteDemo2 {

    public static void main(String[] args) {

        List<List<String>> headers = new ArrayList<>();

        List<String> head0 = new ArrayList<>();
        head0.add("编号");

        List<String> head1 = new ArrayList<>();
        head1.add("姓名");

        List<String> head2 = new ArrayList<>();
        head2.add("年龄");

        List<String> head3 = new ArrayList<>();
        head3.add("姓名");

        List<String> head4 = new ArrayList<>();
        head4.add("描述");

        headers.add(head0);
        headers.add(head1);
        headers.add(head2);
        headers.add(head3);
        headers.add(head4);

        WriteCellStyle cellStyle = new WriteCellStyle();
        cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置字体居中

        //设置字体样式
        WriteFont font = new WriteFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short)12);
        cellStyle.setWriteFont(font);

        // 布局对象
        HorizontalCellStyleStrategy styleStrategy = new HorizontalCellStyleStrategy(cellStyle, cellStyle);


        EasyExcel.write("D:\\111.xls")
                .excelType(ExcelTypeEnum.XLS)
                .head(headers) // 指定表头
                .registerWriteHandler(styleStrategy) // 设置表格样式
                .registerWriteHandler(new MyColumnStyle()) // 设置表格样式
                .sheet("笑傲江湖")
                .doWrite(data());
    }

    // 组装每一行数据
    private static List<List<String>> data() {
        List<List<String>> list = new ArrayList<>();
        list.add(Arrays.asList("1","风清扬","88","男","独孤九剑"));
        list.add(Arrays.asList("2","令狐冲","28","男","易筋经"));
        list.add(Arrays.asList("3","任盈盈","25","女","魔教圣姑"));
        list.add(Arrays.asList("4","任我行","60","男","吸星大法"));
        list.add(Arrays.asList("5","东方不败","48","男/女","葵花宝典"));

        return list;
    }
}
